summaryrefslogtreecommitdiffstats
path: root/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ThemeHelper.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ThemeHelper.kt')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ThemeHelper.kt31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ThemeHelper.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ThemeHelper.kt
index f312e24cf..792f6a253 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ThemeHelper.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ThemeHelper.kt
@@ -10,33 +10,26 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsControllerCompat
-import androidx.preference.PreferenceManager
import kotlin.math.roundToInt
import org.yuzu.yuzu_emu.R
-import org.yuzu.yuzu_emu.YuzuApplication
-import org.yuzu.yuzu_emu.features.settings.model.Settings
+import org.yuzu.yuzu_emu.features.settings.model.BooleanSetting
+import org.yuzu.yuzu_emu.features.settings.model.IntSetting
import org.yuzu.yuzu_emu.ui.main.ThemeProvider
object ThemeHelper {
const val SYSTEM_BAR_ALPHA = 0.9f
- private const val DEFAULT = 0
- private const val MATERIAL_YOU = 1
-
fun setTheme(activity: AppCompatActivity) {
- val preferences = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
setThemeMode(activity)
- when (preferences.getInt(Settings.PREF_THEME, 0)) {
- DEFAULT -> activity.setTheme(R.style.Theme_Yuzu_Main)
- MATERIAL_YOU -> activity.setTheme(R.style.Theme_Yuzu_Main_MaterialYou)
+ when (Theme.from(IntSetting.THEME.getInt())) {
+ Theme.Default -> activity.setTheme(R.style.Theme_Yuzu_Main)
+ Theme.MaterialYou -> activity.setTheme(R.style.Theme_Yuzu_Main_MaterialYou)
}
// Using a specific night mode check because this could apply incorrectly when using the
// light app mode, dark system mode, and black backgrounds. Launching the settings activity
// will then show light mode colors/navigation bars but with black backgrounds.
- if (preferences.getBoolean(Settings.PREF_BLACK_BACKGROUNDS, false) &&
- isNightMode(activity)
- ) {
+ if (BooleanSetting.BLACK_BACKGROUNDS.getBoolean() && isNightMode(activity)) {
activity.setTheme(R.style.ThemeOverlay_Yuzu_Dark)
}
}
@@ -60,8 +53,7 @@ object ThemeHelper {
}
fun setThemeMode(activity: AppCompatActivity) {
- val themeMode = PreferenceManager.getDefaultSharedPreferences(activity.applicationContext)
- .getInt(Settings.PREF_THEME_MODE, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
+ val themeMode = IntSetting.THEME_MODE.getInt()
activity.delegate.localNightMode = themeMode
val windowController = WindowCompat.getInsetsController(
activity.window,
@@ -95,3 +87,12 @@ object ThemeHelper {
windowController.isAppearanceLightNavigationBars = false
}
}
+
+enum class Theme(val int: Int) {
+ Default(0),
+ MaterialYou(1);
+
+ companion object {
+ fun from(int: Int): Theme = entries.firstOrNull { it.int == int } ?: Default
+ }
+}